﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GPSMTest
{
    public partial class AskLineForm : Form
    {
        public AskLineForm()
        {
            InitializeComponent();
        }

        GpsForm MainForm;

        private void AskLineForm_Load(object sender, System.EventArgs e)
        {
            MainForm = (GpsForm)Owner;
            if (MainForm.LineArray.Count > 0)
            {
                ListBoxSend.Items.Clear();
                for (int i = 0; i < MainForm.LineArray.Count; i++)
                {
                    GpsForm.LINESTRUCT linedata1 = (GpsForm.LINESTRUCT)MainForm.LineArray[i];
                    ListBoxSend.Items.Add(linedata1.mode.ToString() + " " + linedata1.linename + " " + linedata1.disname);
                }
            }
        }


        private void button1_Click(object sender, System.EventArgs e)
        {
            if (MainForm.LineArray.Count > 0)
            {
                byte[] tmparray = new byte[100];
                int i = ListBoxSend.SelectedIndex;
                GpsForm.LINESTRUCT linedata1 = (GpsForm.LINESTRUCT)MainForm.LineArray[i];
                tmparray[0] = (byte)linedata1.mode;
                Encoding.Default.GetBytes
                    (linedata1.linename, 0, linedata1.linename.Length, tmparray, 1);
                Encoding.Default.GetBytes(linedata1.disname, 0, linedata1.disname.Length, tmparray, 9);
                MainForm.SendDataToGPS(0x03, 0x4E, tmparray, 0, 30);
            }
            Close();
        }

    }
}
